package com.fz.us.oa.core.dao.com.impl;

import com.fz.us.admin.company.bean.EnumManage;
import com.fz.us.admin.company.bean.FlowEnum;
import com.fz.us.admin.company.dao.impl.BaseFlowDaoImpl;
import com.fz.us.admin.company.entity.User;
import com.fz.us.base.bean.BaseEnum;
import com.fz.us.oa.core.dao.com.ModulePowerDao;
import com.fz.us.oa.core.entity.com.ModulePower;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by dzw on 2017/12/12.
 */
@Repository
public class ModulePowerDaoImpl extends BaseFlowDaoImpl<ModulePower, String> implements ModulePowerDao {
    @Override
    public List<User> getManagers() {
        List<User> userList=getSession().createQuery("FROM User u where u.state=? and u.adminId in (FROM Admin a where a.accountTypeEnum=? and a.state=?)")
                .setParameter(0, BaseEnum.StateEnum.Enable)
                .setParameter(1, EnumManage.AccountTypeEnum.Manager)
                .setParameter(2, BaseEnum.StateEnum.Enable)
                .list();
        return userList;
    }

    @Override
    public ModulePower getModulePowerByUser(User user) {
        List<ModulePower> modulePowerList=getSession().createQuery("FROM ModulePower m where m.state=? and m.creater=? and m.reApply=?")
                .setParameter(0, BaseEnum.StateEnum.Enable)
                .setParameter(1, user)
                .setParameter(2, 0)
                .list();
        if(modulePowerList.size()>0){
            return modulePowerList.get(0);
        }else{
            return null;
        }
    }

    @Override
    public ModulePower getModulePowerPassByUser(User user) {
        List<ModulePower> modulePowerList=getSession().createQuery("FROM ModulePower m where m.state=? and m.creater=? and m.processState=? and m.reApply=?")
                .setParameter(0, BaseEnum.StateEnum.Enable)
                .setParameter(1, user)
                .setParameter(2, FlowEnum.ProcessState.Finished)
                .setParameter(3, 0)
                .list();
        if(modulePowerList.size()>0){
            return modulePowerList.get(0);
        }else{
            return null;
        }
    }

    @Override
    public List<ModulePower> getReModulePowerByUser(User user) {
        List<ModulePower> modulePowerList=getSession().createQuery("FROM ModulePower m where m.state=? and m.creater=? and m.reApply=?")
                .setParameter(0, BaseEnum.StateEnum.Enable)
                .setParameter(1, user)
                .setParameter(2, 1)
                .list();
        return modulePowerList;
    }
}
